package com.jeeplus.modules.work.utils;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.utils.SpringContextHolder;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.sys.entity.SysConfig;
import com.jeeplus.modules.sys.service.SysConfigService;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import com.tencentcloudapi.sms.v20190711.models.SendStatus;
import net.sf.json.JSONObject;
import com.jeeplus.common.utils.CacheUtils;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
import java.text.SimpleDateFormat;
import java.util.*;

/*
异步/公共发送请求类
*/
@Component
public class Send {
    private static final Logger logger = LoggerFactory.getLogger(Send.class);
    private static String name =  "zwfwc";//短信用户名
    private static String pwd =  "ul@2022";//短信密码
    private static String results = "【成都高新区】";
    //短信url
    @Value("${emsUrl}")
    private String emsUrl;
    /**
     *
     * 通过areaId,number异步推送取号排队提醒 短信推送
     * <p>
     *
     * </p>
     *
     * @return
     * @author azj 2021-02-10
     */
    @Async()
    public void sendSMSQueueInfo(String tell,String number,String typeName,List <String> list) {
        if(StringUtils.isNotBlank(tell)){
            String content = "您的排队信息如下 \n排队编号："+number+" \n业务名称："+typeName+" \n等待人数："+list.get(0)+" \n平均办理时间："
                    +list.get(1)+"\n 发送时间："+DateUtils.getDateTime()+results;
            String args="CorpID="+name+"&Pwd="+pwd+"&Mobile="+tell+"&Content="+content+"&Cell=&SendTime=";
            args = HttpRequestUtil.sendPostTell(emsUrl, args);
            logger.error(tell+"_"+number+":"+args);
        }
    }

    /**
     *
     * 排队叫号提醒 短信推送
     * <p>
     *
     * </p>
     *
     * @return
     * @author azj 2021-02-10
     */
    @Async()
    public void sendSMSInfo(String number,String tell, String winNo){
        if(StringUtils.isNotBlank(tell)){
            String content = "请您手持排队编号"+number+"，尽快到"+winNo+"，办理该业务！ \n发送时间："+DateUtils.getDateTime()+results;
            String args="CorpID="+name+"&Pwd="+pwd+"&Mobile="+tell+"&Content="+content+"&Cell=&SendTime=";
            args = HttpRequestUtil.sendPostTell(emsUrl, args);
            logger.error(tell+"_"+number+":"+args);
        }
    }

    /**
     *
     * 通过areaId,number异步推送排队提醒 短信推送
     * <p>
     *
     * </p>
     *
     * @return
     * @author azj 2021-02-10
     */
    @Async()
    public void sendLineSMSInfo(Map<String,Object> m) {
        if(m.get("tell") != null && StringUtils.isNotBlank(String.valueOf(m.get("tell")))){
            String content = "您所办理的"+m.get("typeName")+"，还需等待"+m.get("rn")+"人办理。您的排队编号为"+m.get("number")+", 请您做好办理准备！ \n发送时间："+DateUtils.getDateTime()+results;
            String args="CorpID="+name+"&Pwd="+pwd+"&Mobile="+String.valueOf(m.get("tell"))+"&Content="+content+"&Cell=&SendTime=";
            HttpRequestUtil.sendPostTell(emsUrl, args);
        }
    }

    /**
     *
     * 通过areaId,number异步推送排队提醒 短信推送
     * <p>
     *
     * </p>
     *
     * @return
     * @author azj 2021-02-10
     */
    @Async()
    public void sendSmsVerificationCode(String tell,String code) {
        String content = "感谢使用高馨办为您服务，您的验证码："+code+"\n谢谢您的使用！"+results;
        String args="CorpID="+name+"&Pwd="+pwd+"&Mobile="+tell+"&Content="+content+"&Cell=&SendTime=";
        HttpRequestUtil.sendPostTell(emsUrl, args);
    }

}
